package com.strategy.strategy.context;

import com.strategy.strategy.UploadStrategy;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * ClassName:UploadStrategyContext
 * Package:com.strategy.strategy.context
 * Description
 *
 * @Author:@wenxueshi
 * @Create:2023/7/16 - 22:25
 * @Version:v1.0
 */
//文件上传上下问实现
@Component
@RequiredArgsConstructor
public class UploadStrategyContext {
    /*
    当Map集合的Value为接口类型时，Spring会自动对Map集合进行注入。
    其中map集合的key为接口对应实现类的BeanName
    其中map集合的vlaue为接口对应实现类的实例
     */
    private final Map<String, UploadStrategy> uploadStrategyMap;

    /**
     * 执行上传策略
     *
     * @param file     文件
     * @param
     * @return {@link String} 文件上传全路径
     */
    public String executeUploadStrategy(MultipartFile file, String uploadServiceName) {
        // 执行特点的上传策略
        return uploadStrategyMap.get(uploadServiceName).uploadFile(file);
    }

}

